package com.googlecode.boliang.q09.p2;

public class AGivenSum2 {

	public void searchByGivenSum2(int[] intArray) {
		
		int arrayLength = intArray.length; 
		int pivotValue, leftCur, rightCur; 
		
		System.out.println(intArray.length); 
		
		for (int i = 0; i < arrayLength; i++) {
			
			pivotValue = intArray[i]; 
			leftCur = i + 1; 
			rightCur = arrayLength - 1; 
			
			while (leftCur != rightCur) {
				if (intArray[leftCur] + intArray[rightCur] == pivotValue) {
					System.out.println(intArray[leftCur] + "+" + intArray[rightCur] + "=" + pivotValue); 
					return;
				} else {
					leftCur ++;
					rightCur --;
				}
			}
		}
		System.out.println("No matching was found!");
		return;
	}
}
